package com.boot.web;

import com.boot.model.AuthenticationRequest;
import com.boot.model.UserDto;
import com.boot.service.AuthenticationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

/**
 * @author Chunsheng.Zhang
 * @date 2021/4/8 10:30
 * @description : TODO
 */
@RestController
public class LoginController {


    @Autowired
    private AuthenticationService authenticationService;


    @RequestMapping("/login")
    public String login(AuthenticationRequest authenticationRequest, HttpSession session){
        UserDto userDto = authenticationService.authentication(authenticationRequest);

        //登录成功之后，将用户信息存入session
        session.setAttribute(UserDto.SESSION_USER_KEY,userDto);
        return userDto.getFullname() + " 登录成功!";
    }


}
